//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.pss;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.OrderSet;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.PssProviderCodeDao;
import com.aidong.model.wills.PssProviderCode;
import com.aidong.web.controller.BaseController;
import java.util.Date;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"provider"})
public class ProviderController extends BaseController {
    @Resource
    PssProviderCodeDao pssProviderCodeDao;

    public ProviderController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        return new ModelAndView("pss/provider/list");
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "providerCode",required = false) String providerCode, @RequestParam(value = "providerName",required = false) String providerName, @RequestParam(value = "status",required = false) Integer status, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        if(!this.chkNull(status)) {
            cd.eq("status", status);
        } else {
            cd.gt("status", Integer.valueOf(0));
        }

        ConditionMap mv;
        if(!this.chkNull(providerCode)) {
            mv = new ConditionMap(1);
            mv.like("providerCode", "%" + providerCode + "%");
            cd.addSub(mv);
        }

        if(!this.chkNull(providerName)) {
            mv = new ConditionMap(1);
            mv.like("providerName", "%" + providerName + "%");
            cd.addSub(mv);
        }

        this.pssProviderCodeDao.queryPageList(pg, cd, (new OrderSet()).asc("providerCode"));
        ModelAndView mv1 = new ModelAndView("pss/provider/_list");
        mv1.addObject("list", pg.getResultList());
        mv1.addObject("pg", pg);
        return mv1;
    }

    @RequestMapping({"add"})
    public ModelAndView add() {
        PssProviderCode pssProviderCode = new PssProviderCode();
        pssProviderCode.setStatus(Integer.valueOf(1));
        ModelAndView mv = new ModelAndView("pss/provider/edit");
        mv.addObject("pssProviderCode", pssProviderCode);
        mv.addObject("_oper", "add");
        return mv;
    }

    @RequestMapping({"_add"})
    @ResponseBody
    public String _add(@ModelAttribute("pssProviderCode") PssProviderCode pssProviderCode) {
        if(this.chkNull(pssProviderCode.getProviderCode())) {
            return this.getResult(false, "请输入编码");
        } else if(this.pssProviderCodeDao.exists(pssProviderCode.getProviderCode())) {
            return this.getResult(false, "编码已存在");
        } else {
            if(this.chkNull(pssProviderCode.getStatus())) {
                pssProviderCode.setStatus(Integer.valueOf(1));
            }

            pssProviderCode.setCreateUser(this.getLoginUserCode());
            pssProviderCode.setCreateTime(new Date());
            pssProviderCode.setUpdateTime(new Date());

            try {
                this.pssProviderCodeDao.add(pssProviderCode);
                this.reloadTypeList("pssProviderCode");
                this.addUserLog("新增供应商", "编码:" + pssProviderCode.getProviderCode() + ",名称:" + pssProviderCode.getProviderName());
            } catch (Exception var3) {
                this.log.error("add provider", var3);
                return this.getResult(false, "保存发生错误");
            }

            return this.getResult(true, "保存完成");
        }
    }

    @RequestMapping({"edit"})
    public ModelAndView edit(@RequestParam("providerCode") String providerCode) {
        PssProviderCode pssProviderCode = (PssProviderCode)this.pssProviderCodeDao.getById(providerCode);
        if(pssProviderCode == null) {
            return this.showAlert("没有这个供应商");
        } else {
            ModelAndView mv = new ModelAndView("pss/provider/edit");
            mv.addObject("pssProviderCode", pssProviderCode);
            mv.addObject("_oper", "edit");
            return mv;
        }
    }

    @RequestMapping({"_edit"})
    @ResponseBody
    public String _edit(@ModelAttribute("pssProviderCode") PssProviderCode pssProviderCode) {
        if(this.chkNull(pssProviderCode.getProviderCode())) {
            return this.getResult(false, "没有这个供应商");
        } else {
            PssProviderCode pssProviderCode1 = (PssProviderCode)this.pssProviderCodeDao.getById(pssProviderCode.getProviderCode());
            if(this.chkNull(pssProviderCode.getStatus())) {
                pssProviderCode.setStatus(Integer.valueOf(1));
            }

            if(pssProviderCode1 == null) {
                return this.getResult(false, "没有这个供应商");
            } else {
                pssProviderCode1.setProviderName(pssProviderCode.getProviderName());
                pssProviderCode1.setNote(pssProviderCode.getNote());
                pssProviderCode1.setStatus(pssProviderCode.getStatus());
                pssProviderCode1.setUpdateTime(new Date());

                try {
                    this.pssProviderCodeDao.update(pssProviderCode1);
                    this.reloadTypeList("pssProviderCode");
                    this.addUserLog("修改供应商", "编码:" + pssProviderCode1.getProviderCode() + ",名称:" + pssProviderCode1.getProviderName());
                } catch (Exception var4) {
                    this.log.error("edit provider", var4);
                    return this.getResult(false, "保存发生错误");
                }

                return this.getResult(true, "保存完成");
            }
        }
    }

    @RequestMapping({"_del"})
    @ResponseBody
    public String _del(@RequestParam("providerCode") String providerCode) {
        PssProviderCode pssProviderCode = (PssProviderCode)this.pssProviderCodeDao.getById(providerCode);
        if(pssProviderCode == null) {
            return this.getResult(false, "没有这个供应商");
        } else {
            try {
                this.pssProviderCodeDao.updateStatus(providerCode, 0);
                this.reloadTypeList("pssProviderCode");
                this.addUserLog("删除供应商", "编码:" + pssProviderCode.getProviderCode() + ",名称:" + pssProviderCode.getProviderName());
            } catch (Exception var4) {
                this.log.error("del provider", var4);
                return this.getResult(false, "保存发生错误");
            }

            return this.getResult(true, "删除成功");
        }
    }
}
